package com.apple.frame;

import com.apple.system.service.TextService;
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class FrameMain extends JFrame {
    private final TextService textService;

    public FrameMain(TextService textService) {
        this.textService = textService;
        setVisible(true);
        setSize(300, 200);

        //添加关闭事件监听
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                closeFrame();
            }
        });
    }

    /**
     * 关闭窗口触发逻辑
     */
    private void closeFrame() {
        //todo 停机前应该释放资源
        System.exit(0);
    }

    public void say() {
        textService.sayHello();
    }
}
